<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="theme-color" content="#33474d">
	<title>失落的乐章</title>
	<link rel="stylesheet" href="/css/style.css" />
	
      <link rel="alternate" href="/atom.xml" title="失落的乐章" type="application/atom+xml">
    
</head>

<body>

	<header class="header">
		<nav class="header__nav">
			
				<a href="/archives" class="header__link">Archive</a>
			
				<a href="/tags" class="header__link">Tags</a>
			
				<a href="/atom.xml" class="header__link">RSS</a>
			
		</nav>
		<h1 class="header__title"><a href="/">失落的乐章</a></h1>
		<h2 class="header__subtitle">技术面前，永远都是学生。</h2>
	</header>

	<main>
		
	<span class="different-posts different-posts_earlier">📖 <a href="/page/55">earlier posts</a> 📖</span>




	<article>
	
		<h1><a href="/2017/10/12/2. Linux 命令/13. Linux命令- less/">Linux 命令- less</a></h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/Linux命令/">Linux命令</a>
			</span>
		
	</div>

	

	
		<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;less 工具也是对文件或其它输出进行分页显示的工具，应该说是linux正统查看文件内容的工具，功能极其强大。less 的用法比起 more 更加的有弹性。在 more 的时候，我们并没有办法向前面翻， 只能往后面看，但若使用了 less 时，就可以使用 [pageup] [pagedown] 等按键的功能来往前往后翻看文件，更容易用来查看一个文件的内容！除此之外，在 less 里头可以拥有更多的搜索功能，不止可以向下搜，也可以向上搜。     </p>
<h2 id="命令格式"><a href="#命令格式" class="headerlink" title="命令格式"></a>命令格式</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">less [参数] [文件]</div></pre></td></tr></table></figure>
<h2 id="命令功能"><a href="#命令功能" class="headerlink" title="命令功能"></a>命令功能</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;less 与 more 类似，但使用 less 可以随意浏览文件，而 more 仅能向前移动，却不能向后移动，而且 less 在查看之前不会加载真个文件。</p>
<h2 id="命令参数"><a href="#命令参数" class="headerlink" title="命令参数"></a>命令参数</h2><ul>
<li>-b &lt;缓冲区大小&gt; 设置缓冲区的大小</li>
<li>-e  当文件显示结束后，自动离开</li>
<li>-f  强迫打开特殊文件，例如外围设备代号、目录和二进制文件</li>
<li>-g  只标志最后搜索的关键词</li>
<li>-i  忽略搜索时的大小写</li>
<li>-m  显示类似more命令的百分比</li>
<li>-N  显示每行的行号</li>
<li>-o &lt;文件名&gt; 将less 输出的内容在指定文件中保存起来</li>
<li>-Q  不使用警告音</li>
<li>-s  显示连续空行为一行</li>
<li>-S  行过长时间将超出部分舍弃</li>
<li>-x &lt;数字&gt; 将“tab”键显示为规定的数字空格</li>
<li>/字符串：向下搜索“字符串”的功能</li>
<li>?字符串：向上搜索“字符串”的功能</li>
<li>n：重复前一个搜索（与 / 或 ? 有关）</li>
<li>N：反向重复前一个搜索（与 / 或 ? 有关）</li>
<li>b  向后翻一页</li>
<li>d  向后翻半页</li>
<li>h  显示帮助界面</li>
<li>Q  退出less 命令</li>
<li>u  向前滚动半页</li>
<li>y  向前滚动一行</li>
<li>空格键 滚动一行</li>
<li>回车键 滚动一页</li>
<li>[pagedown]： 向下翻动一页</li>
<li>[pageup]：   向上翻动一页</li>
</ul>
<h2 id="使用实例"><a href="#使用实例" class="headerlink" title="使用实例"></a>使用实例</h2><h3 id="实例1：查看文件"><a href="#实例1：查看文件" class="headerlink" title="实例1：查看文件"></a>实例1：查看文件</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">less log2013.log</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/less/01.png?raw=true" alt="image"><figcaption class="figure__caption">image</figcaption></figure></p>
<h3 id="实例2：ps-查看进程信息并通过-less-分页显示"><a href="#实例2：ps-查看进程信息并通过-less-分页显示" class="headerlink" title="实例2：ps 查看进程信息并通过 less 分页显示"></a>实例2：ps 查看进程信息并通过 less 分页显示</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">ps -ef | less</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/less/02.png?raw=true" alt="image"><figcaption class="figure__caption">image</figcaption></figure></p>
<h3 id="实例3：查看命令示例使用记录并通过-less-分页显示"><a href="#实例3：查看命令示例使用记录并通过-less-分页显示" class="headerlink" title="实例3：查看命令示例使用记录并通过 less 分页显示"></a>实例3：查看命令示例使用记录并通过 less 分页显示</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="built_in">history</span> | less</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div></pre></td><td class="code"><pre><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># history | less</span></div><div class="line">22  scp -r tomcat6.0.32 root@192.168.120.203:/opt/soft</div><div class="line">23  <span class="built_in">cd</span> ..</div><div class="line">24  scp -r web root@192.168.120.203:/opt/</div><div class="line">25  <span class="built_in">cd</span> soft</div><div class="line">26  ls</div><div class="line">27  scp -r jdk1.6.0_16/ root@192.168.120.203:/opt/soft</div><div class="line">28  clear</div><div class="line">29  vim /etc/profile</div><div class="line">30  vim /etc/profile</div><div class="line">31  <span class="built_in">cd</span> tomcat6.0.32/bin/</div><div class="line">32  ls</div><div class="line">33  ./shutdown.sh</div><div class="line">34  ./startup.sh</div><div class="line">35  vim startup.sh</div><div class="line">36  ls</div><div class="line">37  <span class="built_in">echo</span> <span class="variable">$JAVA_HOME</span></div><div class="line">38  java</div><div class="line">39  ls</div><div class="line">40  ls</div><div class="line">41  clear</div><div class="line">42  <span class="built_in">cd</span> /opt</div><div class="line">43  ls</div><div class="line">44  cp apache-tomcat-6.0.32.tar.gz soft/</div><div class="line">45  ls</div><div class="line">46  rm -f apache-tomcat-6.0.32.tar.gz </div><div class="line">47  ls</div><div class="line">48  <span class="built_in">cd</span> soft</div><div class="line">49  ls</div><div class="line">50  tar -vzf apache-tomcat-6.0.32.tar.gz </div><div class="line">51  tar -vzfx apache-tomcat-6.0.32.tar.gz </div><div class="line">52  tar -zxvf apache-tomcat-6.0.32.tar.gz </div><div class="line">53  ls</div><div class="line">54  <span class="built_in">cd</span> apache-tomcat-6.0.32</div><div class="line">55  ls</div><div class="line">56  <span class="built_in">cd</span> ..</div><div class="line">57  mv apache-tomcat-6.0.32 tomcat6.0.32</div><div class="line">58  ls</div><div class="line">59  <span class="built_in">cd</span> tomcat6.0.32/</div><div class="line">60  ls</div></pre></td></tr></table></figure>
<h3 id="实例4：浏览多个文件"><a href="#实例4：浏览多个文件" class="headerlink" title="实例4：浏览多个文件"></a>实例4：浏览多个文件</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">less log2013.log log2014.log</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong>   </p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/less/03.png?raw=true" alt="image"><figcaption class="figure__caption">image</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>说明</strong></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;输出：n 后，切换到 log2014.log</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;输出：p 后，切换到 log2013.log    </p>
<h2 id="附加备注"><a href="#附加备注" class="headerlink" title="附加备注"></a>附加备注</h2><h3 id="1-全屏导航"><a href="#1-全屏导航" class="headerlink" title="1.全屏导航"></a>1.全屏导航</h3><ul>
<li>ctrl + F - 向前移动一屏</li>
<li>ctrl + B - 向后移动一屏</li>
<li>ctrl + D - 向前移动半屏</li>
<li>ctrl + U - 向后移动半屏</li>
</ul>
<h3 id="2-单行导航"><a href="#2-单行导航" class="headerlink" title="2.单行导航"></a>2.单行导航</h3><ul>
<li>j - 向前移动一行</li>
<li>k - 向后移动一行</li>
</ul>
<h3 id="3-其他导航"><a href="#3-其他导航" class="headerlink" title="3.其他导航"></a>3.其他导航</h3><ul>
<li>G - 移动到最后一行</li>
<li>g - 移动到第一行</li>
<li>q / ZZ - 退出 less 命令    </li>
</ul>
<h3 id="4-其他有用的命令"><a href="#4-其他有用的命令" class="headerlink" title="4.其他有用的命令"></a>4.其他有用的命令</h3><ul>
<li>v - 使用配置的编辑器编辑当前文件</li>
<li>h - 显示 less 的帮助文档</li>
<li>&amp;pattern - 仅显示匹配模式的行，而不是整个文件</li>
</ul>
<h3 id="5-标记导航"><a href="#5-标记导航" class="headerlink" title="5.标记导航"></a>5.标记导航</h3><ul>
<li>当使用 less 查看大文件时，可以在任何一个位置作标记，可以通过命令导航到标有特定标记的文档位置：</li>
<li>ma - 使用 a 标记文本的当前位置</li>
<li>‘a - 导航到标记 a 处</li>
</ul>

	

	

</article>




	<article>
	
		<h1><a href="/2017/10/12/2. Linux 命令/11. Linux 命令- nl/">Linux 命令- nl</a></h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/Linux命令/">Linux命令</a>
			</span>
		
	</div>

	

	
		<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;nl命令在linux系统中用来计算文件中行号。nl 可以将输出的文件内容自动的加上行号！其默认的结果与 cat -n 有点不太一样， nl 可以将行号做比较多的显示设计，包括位数与是否自动补齐 0 等等的功能。      </p>
<h2 id="1．命令格式："><a href="#1．命令格式：" class="headerlink" title="1．命令格式："></a>1．命令格式：</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">nl [选项]... [文件]...</div></pre></td></tr></table></figure>
<h2 id="2．命令参数："><a href="#2．命令参数：" class="headerlink" title="2．命令参数："></a>2．命令参数：</h2><ul>
<li>-b  ：指定行号指定的方式，主要有两种：    <ul>
<li>-b a ：表示不论是否为空行，也同样列出行号(类似 cat -n)；    </li>
<li>-b t ：如果有空行，空的那一行不要列出行号(默认值)；</li>
</ul>
</li>
<li>-n  ：列出行号表示的方法，主要有三种：    <ul>
<li>-n ln ：行号在萤幕的最左方显示；    </li>
<li>-n rn ：行号在自己栏位的最右方显示，且不加 0 ；    </li>
<li>-n rz ：行号在自己栏位的最右方显示，且加 0 ；</li>
</ul>
</li>
<li>-w  ：行号栏位的占用的位数。</li>
<li>-p 在逻辑定界符处不重新开始计算。 </li>
</ul>
<h2 id="3．命令功能："><a href="#3．命令功能：" class="headerlink" title="3．命令功能："></a>3．命令功能：</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;nl 命令读取 File 参数（缺省情况下标准输入），计算输入中的行号，将计算过的行号写入标准输出。 在输出中，nl 命令根据您在命令行中指定的标志来计算左边的行。 输入文本必须写在逻辑页中。每个逻辑页有头、主体和页脚节（可以有空节）。 除非使用 -p 标志，nl 命令在每个逻辑页开始的地方重新设置行号。 可以单独为头、主体和页脚节设置行计算标志（例如，头和页脚行可以被计算然而文本行不能）。</p>
<h2 id="4．使用实例："><a href="#4．使用实例：" class="headerlink" title="4．使用实例："></a>4．使用实例：</h2><h3 id="实例1：用-nl-列出-log2012-log-的内容"><a href="#实例1：用-nl-列出-log2012-log-的内容" class="headerlink" title="实例1：用 nl 列出 log2012.log 的内容"></a>实例1：用 nl 列出 log2012.log 的内容</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">nl log2012.log</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># nl log2012.log </span></div><div class="line">1  2012-01</div><div class="line">2  2012-02</div><div class="line"> </div><div class="line"></div><div class="line">3  ======</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment">#</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>说明：</strong></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;文件中的空白行，nl 不会加上行号    </p>
<h3 id="实例2：用-nl-列出-log2012-log-的内容，空本行也加上行号"><a href="#实例2：用-nl-列出-log2012-log-的内容，空本行也加上行号" class="headerlink" title="实例2：用 nl 列出 log2012.log 的内容，空本行也加上行号"></a>实例2：用 nl 列出 log2012.log 的内容，空本行也加上行号</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">nl -b a log2012.log</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># nl -b a log2012.log </span></div><div class="line">1  2012-01</div><div class="line">2  2012-02</div><div class="line">3</div><div class="line">4</div><div class="line">5  ======</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment">#</span></div></pre></td></tr></table></figure>
<h3 id="实例3：让行号前面自动补上0-统一输出格式"><a href="#实例3：让行号前面自动补上0-统一输出格式" class="headerlink" title="实例3：让行号前面自动补上0,统一输出格式"></a>实例3：让行号前面自动补上0,统一输出格式</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令：</strong></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div></pre></td><td class="code"><pre><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># nl -b a -n rz log2014.log </span></div><div class="line">000001  2014-01</div><div class="line">000002  2014-02</div><div class="line">000003  2014-03</div><div class="line">000004  2014-04</div><div class="line">000005  2014-05</div><div class="line">000006  2014-06</div><div class="line">000007  2014-07</div><div class="line">000008  2014-08</div><div class="line">000009  2014-09</div><div class="line">000010  2014-10</div><div class="line">000011  2014-11</div><div class="line">000012  2014-12</div><div class="line">000013  =======</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># nl -b a -n rz -w 3 log2014.log </span></div><div class="line">001     2014-01</div><div class="line">002     2014-02</div><div class="line">003     2014-03</div><div class="line">004     2014-04</div><div class="line">005     2014-05</div><div class="line">006     2014-06</div><div class="line">007     2014-07</div><div class="line">008     2014-08</div><div class="line">009     2014-09</div><div class="line">010     2014-10</div><div class="line">011     2014-11</div><div class="line">012     2014-12</div><div class="line">013     =======</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>说明：</strong></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;nl -b a -n rz 命令行号默认为六位，要调整位数可以加上参数 -w 3 调整为3位。</p>

	

	

</article>




	<article>
	
		<h1><a href="/2017/10/12/2. Linux 命令/1. Linux 命令-cd/">Linux 命令- cd</a></h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/Linux命令/">Linux命令</a>
			</span>
		
	</div>

	

	
		<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Linux cd 命令可以说是Linux中最基本的命令语句，其他的命令语句要进行操作，都是建立在使用 cd 命令上的。所以，学习Linux 常用命令，首先就要学好 cd 命令的使用方法技巧。</p>
<h2 id="1-命令格式"><a href="#1-命令格式" class="headerlink" title="1.命令格式"></a>1.命令格式</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="built_in">cd</span>  [目录名]</div></pre></td></tr></table></figure>
<h2 id="2-命令功能"><a href="#2-命令功能" class="headerlink" title="2.命令功能"></a>2.命令功能</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;切换当前目录至dirName  </p>
<h2 id="3-常用范例"><a href="#3-常用范例" class="headerlink" title="3.常用范例"></a>3.常用范例</h2><h3 id="例1：进入系统根目录"><a href="#例1：进入系统根目录" class="headerlink" title="例1：进入系统根目录"></a>例1：进入系统根目录</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="built_in">cd</span> /</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@localhost ~]<span class="comment"># cd /</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>说明：</strong>进入系统根目录,上面命令执行完后拿ls命令看一下，当前目录已经到系统根目录了</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="built_in">cd</span> ..</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;或者</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="built_in">cd</span> .. //</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出:</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">[root@localhost soft]<span class="comment"># pwd</span></div><div class="line">/opt/soft</div><div class="line">[root@localhost soft]<span class="comment"># cd ..</span></div><div class="line">[root@localhost opt]<span class="comment"># cd ..//</span></div><div class="line">[root@localhost /]<span class="comment"># pwd</span></div><div class="line">/</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>说明：</strong> </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;进入系统根目录可以使用“ cd .. ”一直退，就可以到达根目录</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="built_in">cd</span> ../.. //</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">[root@localhost soft]<span class="comment"># pwd</span></div><div class="line">/opt/soft</div><div class="line">[root@localhost soft]<span class="comment"># cd ../.. //</span></div><div class="line">[root@localhost /]<span class="comment"># pwd</span></div><div class="line">/</div><div class="line">[root@localhost /]<span class="comment">#</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>说明：</strong> 使用cd 命令实现进入当前目录的父目录的父目录。 </p>
<h3 id="例2：使用-cd-命令进入当前用户主目录"><a href="#例2：使用-cd-命令进入当前用户主目录" class="headerlink" title="例2：使用 cd 命令进入当前用户主目录"></a>例2：使用 cd 命令进入当前用户主目录</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;“当前用户主目录”和“系统根目录”是两个不同的概念。进入当前用户主目录有两个方法。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令1：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="built_in">cd</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">1 [root@localhost soft]<span class="comment"># pwd</span></div><div class="line">2 /opt/soft</div><div class="line">3 [root@localhost soft]<span class="comment"># cd</span></div><div class="line">4 [root@localhost ~]<span class="comment"># pwd</span></div><div class="line">5 /root</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令2：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="built_in">cd</span> ~</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">[root@localhost ~]<span class="comment"># cd /opt/soft/</span></div><div class="line">[root@localhost soft]<span class="comment"># pwd</span></div><div class="line">/opt/soft</div><div class="line">[root@localhost soft]<span class="comment"># cd ~</span></div><div class="line">[root@localhost ~]<span class="comment"># pwd</span></div><div class="line">/root</div></pre></td></tr></table></figure>
<h3 id="例3：跳转到指定目录"><a href="#例3：跳转到指定目录" class="headerlink" title="例3：跳转到指定目录"></a>例3：跳转到指定目录</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="built_in">cd</span> /opt/soft</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">[root@localhost ~]<span class="comment"># cd /opt/soft</span></div><div class="line">[root@localhost soft]<span class="comment"># pwd</span></div><div class="line">/opt/soft</div><div class="line">[root@localhost soft]<span class="comment"># cd jdk1.6.0_16/</span></div><div class="line">[root@localhost jdk1.6.0_16]<span class="comment"># pwd</span></div><div class="line">/opt/soft/jdk1.6.0_16</div><div class="line">[root@localhost jdk1.6.0_16]<span class="comment">#</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>说明：</strong></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;跳转到指定目录，从根目录开始，目录名称前加 / ,当前目录内的子目录直接写名称即可        </p>
<h3 id="例4：返回进入此目录之前所在的目录"><a href="#例4：返回进入此目录之前所在的目录" class="headerlink" title="例4：返回进入此目录之前所在的目录"></a>例4：返回进入此目录之前所在的目录</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="built_in">cd</span> -</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">[root@localhost soft]<span class="comment"># pwd</span></div><div class="line">/opt/soft</div><div class="line">[root@localhost soft]<span class="comment"># cd -</span></div><div class="line">/root</div><div class="line">[root@localhost ~]<span class="comment"># pwd</span></div><div class="line">/root</div><div class="line">[root@localhost ~]<span class="comment"># cd -</span></div><div class="line">/opt/soft</div><div class="line">[root@localhost soft]<span class="comment">#</span></div></pre></td></tr></table></figure>
<h3 id="例5：把上个命令的参数作为cd参数使用。"><a href="#例5：把上个命令的参数作为cd参数使用。" class="headerlink" title="例5：把上个命令的参数作为cd参数使用。"></a>例5：把上个命令的参数作为cd参数使用。</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="built_in">cd</span> !$</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">[root@localhost soft]<span class="comment"># cd !$</span></div><div class="line"><span class="built_in">cd</span> -</div><div class="line">/root</div><div class="line">[root@localhost ~]<span class="comment"># cd !$</span></div><div class="line"><span class="built_in">cd</span> -</div><div class="line">/opt/soft</div><div class="line">[root@localhost soft]<span class="comment">#</span></div></pre></td></tr></table></figure>

	

	

</article>




	<article>
	
		<h1><a href="/2017/10/12/2. Linux 命令/10. Linux 命令- cat/">Linux 命令- cat</a></h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/Linux命令/">Linux命令</a>
			</span>
		
	</div>

	

	
		<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;cat命令的用途是连接文件或标准输入并打印。这个命令常用来显示文件内容，或者将几个文件连接起来显示，或者从标准输入读取内容并显示，它常与重定向符号配合使用。 </p>
<h2 id="1．命令格式："><a href="#1．命令格式：" class="headerlink" title="1．命令格式："></a>1．命令格式：</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">cat [选项] [文件]</div></pre></td></tr></table></figure>
<h2 id="2．命令功能："><a href="#2．命令功能：" class="headerlink" title="2．命令功能："></a>2．命令功能：</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>cat主要有三大功能：</strong></p>
<ol>
<li>一次显示整个文件:cat filename</li>
<li>从键盘创建一个文件:cat &gt; filename 只能创建新文件,不能编辑已有文件.</li>
<li>将几个文件合并为一个文件:cat file1 file2 &gt; file</li>
</ol>
<h2 id="3．命令参数："><a href="#3．命令参数：" class="headerlink" title="3．命令参数："></a>3．命令参数：</h2><ul>
<li>-A –show-all 等价于 -vET</li>
<li>-b –number-nonblank 对非空输出行编号</li>
<li>-e  等价于 -vE</li>
<li>-E –show-ends 在每行结束处显示 $</li>
<li>-n –number 对输出的所有行编号,由1开始对所有输出的行数编号</li>
<li>-s –squeeze-blank 有连续两行以上的空白行，就代换为一行的空白行 </li>
<li>-t 与 -vT 等价</li>
<li>-T –show-tabs 将跳格字符显示为 ^I</li>
<li>-u (被忽略)</li>
<li>-v –show-nonprinting 使用 ^ 和 M- 引用，除了 LFD 和 TAB 之外</li>
</ul>
<h2 id="4．使用实例："><a href="#4．使用实例：" class="headerlink" title="4．使用实例："></a>4．使用实例：</h2><h3 id="实例1：把-log2012-log-的文件内容加上行号后输入-log2013-log-这个文件里"><a href="#实例1：把-log2012-log-的文件内容加上行号后输入-log2013-log-这个文件里" class="headerlink" title="实例1：把 log2012.log 的文件内容加上行号后输入 log2013.log 这个文件里"></a>实例1：把 log2012.log 的文件内容加上行号后输入 log2013.log 这个文件里</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">cat -n log2012.log log2013.log</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div></pre></td><td class="code"><pre><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># cat log2012.log </span></div><div class="line">2012-01</div><div class="line">2012-02</div><div class="line"></div><div class="line"></div><div class="line">======</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># cat log2013.log </span></div><div class="line">2013-01</div><div class="line">2013-02</div><div class="line"></div><div class="line"></div><div class="line">2013-03</div><div class="line">======</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># cat -n log2012.log log2013.log </span></div><div class="line">1  2012-01</div><div class="line">2  2012-02</div><div class="line">3</div><div class="line">4</div><div class="line">5  ======</div><div class="line">6  2013-01</div><div class="line">7  2013-02</div><div class="line">8</div><div class="line">9</div><div class="line">10  2013-03</div><div class="line">11  ======</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment">#</span></div></pre></td></tr></table></figure>
<h3 id="实例2：把-log2012-log-和-log2013-log-的文件内容加上行号（空白行不加）之后将内容附加到-log-log-里。"><a href="#实例2：把-log2012-log-和-log2013-log-的文件内容加上行号（空白行不加）之后将内容附加到-log-log-里。" class="headerlink" title="实例2：把 log2012.log 和 log2013.log 的文件内容加上行号（空白行不加）之后将内容附加到 log.log 里。"></a>实例2：把 log2012.log 和 log2013.log 的文件内容加上行号（空白行不加）之后将内容附加到 log.log 里。</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">cat -b log2012.log log2013.log log.log</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># cat -b log2012.log log2013.log log.log</span></div><div class="line">1  2012-01</div><div class="line">2  2012-02</div><div class="line">3  ======</div><div class="line">4  2013-01</div><div class="line">5  2013-02</div><div class="line">6  2013-03</div><div class="line">7  ======[root@localhost <span class="built_in">test</span>]<span class="comment">#</span></div></pre></td></tr></table></figure>
<h3 id="实例3：把-log2012-log-的文件内容加上行号后输入-log-log-这个文件里"><a href="#实例3：把-log2012-log-的文件内容加上行号后输入-log-log-这个文件里" class="headerlink" title="实例3：把 log2012.log 的文件内容加上行号后输入 log.log 这个文件里"></a>实例3：把 log2012.log 的文件内容加上行号后输入 log.log 这个文件里</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">cat log.log</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># cat log.log </span></div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># cat -n log2012.log &gt; log.log</span></div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># cat -n log.log </span></div><div class="line">1  2012-01</div><div class="line">2  2012-02</div><div class="line">3</div><div class="line">4</div><div class="line">5  ======</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment">#</span></div></pre></td></tr></table></figure>
<h3 id="实例4：使用here-doc来生成文件"><a href="#实例4：使用here-doc来生成文件" class="headerlink" title="实例4：使用here doc来生成文件"></a>实例4：使用here doc来生成文件</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div></pre></td><td class="code"><pre><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># cat &gt;log.txt &lt;&lt;EOF</span></div><div class="line">&gt; Hello</div><div class="line">&gt; World</div><div class="line">&gt; Linux</div><div class="line">&gt; PWD=$(<span class="built_in">pwd</span>)</div><div class="line">&gt; EOF</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># ls -l log.txt </span></div><div class="line">-rw-r--r-- 1 root root 37 10-28 17:07 log.txt</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># cat log.txt </span></div><div class="line">Hello</div><div class="line">World</div><div class="line">Linux</div><div class="line">PWD=/opt/soft/<span class="built_in">test</span></div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment">#</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>说明：</strong></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;注意粗体部分，here doc可以进行字符串替换。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>备注：</strong></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>tac (反向列示)</strong></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">tac log.txt</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># tac log.txt </span></div><div class="line">PWD=/opt/soft/<span class="built_in">test</span></div><div class="line">Linux</div><div class="line">World</div><div class="line">Hello</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>说明：</strong></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;tac 是将 cat 反写过来，所以他的功能就跟 cat 相反， cat 是由第一行到最后一行连续显示在萤幕上，而 tac 则是由最后一行到第一行反向在萤幕上显示出来！</p>

	

	

</article>




	<article>
	
		<h1><a href="/2017/10/12/1. Linux 基础/9. Linux 增加删除用户/">Linux 增加删除用户</a></h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/Linux/">Linux</a>
			</span>
		
	</div>

	

	
		<h2 id="1-增加用户"><a href="#1-增加用户" class="headerlink" title="1.增加用户"></a>1.增加用户</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令：useradd</strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>语法：</strong>    </p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">useradd [-u UID] [-g GID] [-d HOME] [-M] [-s]</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>参数：</strong></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>-u</strong>：自定义UID</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>-g</strong>：使其属于已经存在的某个组，后面可以分组 id ，也可以分组名</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>-d</strong>：自定义用户的家目录</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>-M</strong>：不建立家目录</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>-s</strong>：自定义 shell</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;‘useradd’ 不加任何选项直接跟用户名，则会创建一个跟用户名同样名字的组。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">[root@localhost ~]<span class="comment"># useradd test10</span></div><div class="line">[root@localhost ~]<span class="comment"># tail -n1 /etc/passwd</span></div><div class="line">test10:x:500:503::/home/test10:/bin/bash</div><div class="line">[root@localhost ~]<span class="comment"># tail -n1 /etc/group</span></div><div class="line">test10:x:503:</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;‘-g’ 选项后面跟一个不存在的gid会报错，提示该组不存在。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line">[root@localhost ~]<span class="comment"># useradd -u510 -g 513 -M -s /sbin/nologin user11</span></div><div class="line">useradd: group <span class="string">'513'</span> does not exist</div><div class="line">[root@localhost ~]<span class="comment"># useradd -u510 -g 502 -M -s /sbin/nologin user11</span></div><div class="line">[root@localhost ~]<span class="comment"># useradd -u511 -g grptest1 user12</span></div><div class="line">[root@localhost ~]<span class="comment"># tail -n2 /etc/passwd</span></div><div class="line">user11:x:510:502::/home/user11:/sbin/nologin</div><div class="line">user12:x:511:502::/home/user12:/bin/bash</div><div class="line">[root@localhost ~]<span class="comment"># tail -n2 /etc/group</span></div><div class="line">grptest1:x:502:</div><div class="line">test10:x:503:</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;‘-M’ 选项加上后则不建立用户家目录，但是在/etc/passwd文件中仍然有这个字段。但是使用 <code>ls /home/user11</code> 查看一下会提示该目录不存在。所以 ‘-M’ 选项的作用只是不创建那个目录。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[root@localhost ~]<span class="comment"># ls /home/user11</span></div><div class="line">ls: 无法访问/home/user11: 没有那个文件或目录</div></pre></td></tr></table></figure>
<h2 id="2-删除账户"><a href="#2-删除账户" class="headerlink" title="2.删除账户"></a>2.删除账户</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令：useradd</strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>语法：</strong>  </p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">userdel [-r] username</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;‘-r’ 选项的作用只有一个，就是删除账户的时候连带账户的家目录一起删除。 </p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line">[root@localhost ~]<span class="comment"># ls -ld /home/user12</span></div><div class="line">drwx------ 3 user12 grptest1 4096 5月  11 07:12 /home/user12</div><div class="line">[root@localhost ~]<span class="comment"># userdel user12</span></div><div class="line">[root@localhost ~]<span class="comment"># ls -ld /home/user12</span></div><div class="line">drwx------ 3 511 grptest1 4096 5月  11 07:12 /home/user12</div><div class="line">[root@localhost ~]<span class="comment"># ls -ld /home/test10/</span></div><div class="line">drwx------ 3 test10 test10 4096 5月  11 07:09 /home/test10/</div><div class="line">[root@localhost ~]<span class="comment"># userdel  -r test10</span></div><div class="line">[root@localhost ~]<span class="comment"># ls -ld /home/test10/</span></div><div class="line">ls: 无法访问/home/test10/: 没有那个文件或目录</div></pre></td></tr></table></figure>

	

	

</article>




	<article>
	
		<h1><a href="/2017/10/12/1. Linux 基础/8. Linux 增加和删除用户组/">Linux 增加和删除用户组</a></h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/Linux/">Linux</a>
			</span>
		
	</div>

	

	
		<h2 id="1-新增一个组"><a href="#1-新增一个组" class="headerlink" title="1.新增一个组"></a>1.新增一个组</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令：groupadd</strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>语法：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">groupadd [-g GID] groupname</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;不加“-g”选项则按照系统默认的 gid 创建组，跟用户一样，gid 也是从 500 开始的。<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;示例：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">[root@localhost ~]<span class="comment"># groupadd grptest1</span></div><div class="line">[root@localhost ~]<span class="comment"># tail -n1 /etc/group</span></div><div class="line">grptest1:x:502:</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;“-g”选项可以自定义 gid。<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;示例：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">[root@localhost ~]<span class="comment"># groupadd -g 511 grptest2</span></div><div class="line">[root@localhost ~]<span class="comment"># tail -n2 /etc/group</span></div><div class="line">grptest1:x:502:</div><div class="line">grptest2:x:511:</div></pre></td></tr></table></figure>
<h2 id="2-删除组"><a href="#2-删除组" class="headerlink" title="2.删除组"></a>2.删除组</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令：groupdel</strong>  </p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">[root@localhost ~]<span class="comment"># groupdel grptest2</span></div><div class="line">[root@localhost ~]<span class="comment"># tail -n3 /etc/group</span></div><div class="line">testgroup:x:500:</div><div class="line">user1:x:501:</div><div class="line">grptest1:x:502:</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;该命令没有特殊选项，但有一种情况不能删除组：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[root@localhost ~]<span class="comment"># groupdel user1</span></div><div class="line">groupdel: cannot remove the primary group of user <span class="string">'user1'</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;这是因为 user1 组中包含 user1 账户，只有删除 user1 账户后才可以删除组。</p>

	

	

</article>




	<article>
	
		<h1><a href="/2017/10/12/1. Linux 基础/72. 进程与线程/">进程与线程</a></h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/Linux/">Linux</a>
			</span>
		
	</div>

	

	
		<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;计算机上运行的程序都会有进程，你可以打开windows的进程管理器来查看系统所有的进程信息，而linux可以使用top或者ps来查看所有的进程信息。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;线程是比进程还要细分的一个单元，它在进程里面，一个进程下面可以有多个线程。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;下表为进程和线程的主要区别：</p>
<table>
<thead>
<tr>
<th>项目</th>
<th>进程</th>
<th>线程</th>
</tr>
</thead>
<tbody>
<tr>
<td>unit</td>
<td>分配系统资源(cpu时间、内存等）的基本单位</td>
<td>进程内的一个执行单元，CPU调度和分派的基本单位</td>
</tr>
<tr>
<td>地址空间</td>
<td>有独立的地址空间</td>
<td>和同进程内的其他线程共享地址空间</td>
</tr>
<tr>
<td>健壮性</td>
<td>很健壮，一个进程崩溃对其他进程没有影响</td>
<td>不健壮，相同进程内，一个线程崩溃（意味着进程崩溃），其他线程也会崩溃</td>
</tr>
<tr>
<td>调度（切换）</td>
<td>进程上下文切换，资源耗费大</td>
<td>轻量级进程切换，不用重新加载内存，一个进程内的线程切换要比不同进程内的线程切换快5-50倍</td>
</tr>
<tr>
<td>创建</td>
<td>拷贝父进程的地址空间，耗时较长</td>
<td>直接创建，比进程创建要快10-100倍</td>
</tr>
<tr>
<td>通信</td>
<td>进程间通信，用到IPC通信机制（共享内存、socket、信号、管道等）</td>
<td>可以直接和相同进程内的其他线程通信</td>
</tr>
<tr>
<td>编程容易</td>
<td>多进程间耦合性较小，比较容易</td>
<td>线程间耦合度较大，共享全局变量，需要考虑关键变量的互斥操作</td>
</tr>
</tbody>
</table>

	

	

</article>




	<article>
	
		<h1><a href="/2017/10/12/1. Linux 基础/73.利用iptables防止syn flood攻击/">利用iptables防止syn flood攻击</a></h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/Linux/">Linux</a>
			</span>
		
	</div>

	

	
		<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">iptables -N syn-flood</div><div class="line">iptables -A syn-flood -m <span class="built_in">limit</span> --<span class="built_in">limit</span> 50/s --<span class="built_in">limit</span>-burst 10 -j RETURN</div><div class="line">iptables -A syn-flood -j DROP</div><div class="line">iptables -I INPUT -j syn-flood</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;解释：</p>
<ul>
<li>-N 创建一个条新的链</li>
<li>–limit 50/s 表示每秒50次; 1/m 则为每分钟一次</li>
<li>–limit-burst 表示允许触发 limit 限制的最大包个数 (预设5)，它就像是一个容器，最多装10个，超过10个就装不下了，这些包就给后面的规则了</li>
<li>-I INPUT -j syn-flood  把INPUT的包交给syn-flood链处理</li>
</ul>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;这里的–limit-burst=10相当于说最开始我有10个可以匹配的包去转发，然后我匹配的包的个数是根据–limit=50/s进行限制的，也就是每秒限制转发50个数据包，多余的会被下面符合要求的DROP规则去处理，进行丢弃，这样就实现了对数据包的限速问题。</p>

	

	

</article>




	<article>
	
		<h1><a href="/2017/10/12/1. Linux 基础/71. 郁闷，又断开了！！！/">郁闷，又断开了！！！</a></h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/Linux/">Linux</a>
			</span>
		
	</div>

	

	
		<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;有时，我们想在一个会话窗口中运行一个较长时间的任务，比如压缩一个比较大的目录，或者编译安装mysql，时间会很久，但是我们不能保证中途过程这个会话一直保持连接。万一断开，你岂不是又要重新开始？</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;如果使用screen，则我们可随时查看这个会话中的任务情况。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;打开一个会话，然后输入screen命令，回车。此时就进入了screen界面了。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;然后就跟平时一样，输入要执行的任务命令，比如：查看日志</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">tail -f /var/<span class="built_in">log</span>/messages</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;因为这个会话是活动状态，所以我们无法停止，那么此时需要 这样操作 ： </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;CTRL + A ，然后按 d键，那么就退出了这个screen界面</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;要想运行多个 screen，则我们还可以继续输入screen命令，回车，接下来的步骤和前面是一样的。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">screen -ls  // 查看目前所有的screen任务</div><div class="line">screen -r id // 这个id是screen -ls 时 看到的一个数字，如果只有一个，可以省略掉id号</div></pre></td></tr></table></figure>

	

	

</article>




	<article>
	
		<h1><a href="/2017/10/12/1. Linux 基础/70. 如何知道你的linux是什么时候安装的/">如何知道你的linux是什么时候安装的</a></h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/Linux/">Linux</a>
			</span>
		
	</div>

	

	
		<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;在安装系统时，每个分区下都会有一个 lost+found，而且这个目录的创建时间是和该分区创建的时间一样的。所以如果想知道你的系统是什么时候安装的，只需要看这个目录的创建时间即可。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;通常情况下，我们分区都会把 /boot 单独分一个区，所以你只要查看 /boot/lost+found 这个目录的创建时间即可。比较简单的方法是：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">ls -ld  /boot/lost+found</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;如果你的/boot/不是单独分区，那么就看一下 / 下的吧</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">ls -ld  /lost+found</div></pre></td></tr></table></figure>
	

	

</article>





	<span class="different-posts">📖 <a href="/page/57">more posts</a> 📖</span>



	</main>

	<footer class="footer">
	<div class="footer-content">
		
	      <div class="footer__element">
	<p>Hi there, <br />welcome to my Blog glad you found it. Have a look around, will you?</p>
</div>

	    
	      <div class="footer__element">
	<h5>Check out</h5>
	<ul class="footer-links">
		<li class="footer-links__link"><a href="/archives">Archive</a></li>
		
		  <li class="footer-links__link"><a href="/atom.xml">RSS</a></li>
	    
		<li class="footer-links__link"><a href="/about">about page</a></li>
		<li class="footer-links__link"><a href="/tags">Tags</a></li>
		<li class="footer-links__link"><a href="/categories">Categories</a></li>
	</ul>
</div>

	    

		<div class="footer-credit">
			<span>© 2017 失落的乐章 | Powered by <a href="https://hexo.io/">Hexo</a> | Theme <a href="https://github.com/HoverBaum/meilidu-hexo">MeiliDu</a></span>
		</div>

	</div>


</footer>



</body>

</html>
